﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using PPAP.BO;

namespace PPAP.Web.Master
{
    public partial class MailTemplateList : PageBase
    {
        MailTemplateBO mbo = new MailTemplateBO();
        LogBO lbo = new LogBO();
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                //if (Request.QueryString["DID"] != null)
                //{
                //    LoadDep(Request.QueryString["DID"].ToString());
                //}
                LoadData();
            }
            if (Request.QueryString["deid"] != null)
            {
                dele(Request.QueryString["deid"].ToString());
            }
        }

        private void dele(string id)
        {
            int num = mbo.Delete(int.Parse(id));
            lbo.WriteLog(CurrentUser.Id, "Delete MailTemplate");
            if (num > 0)
                AlertMessage("Deleted successful");
            LoadData();
        }

        private void LoadData()
        {
            DataSet ds = mbo.GetList("");
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }

        //private void LoadDep(string id)
        //{
        //    Model.Department d = bo.GetModel(int.Parse(id));
        //    txtDepartment.Text = d.DEPARTMENT;
        //    txtDescription.Text = d.DESCRIPTION;
        //    Button1.Text = "Save";
        //}

        //protected void Button1_Click(object sender, EventArgs e)
        //{
        //    Model.Department d = new Model.Department();
        //    int num = 0;
        //    if (txtDescription.Text.Trim() == "" || txtDepartment.Text.Trim() == "")
        //    {
        //        AlertMessage("The text frame not is empty");
        //        return;
        //    }
        //    d.DESCRIPTION = txtDescription.Text;
        //    d.DEPARTMENT = txtDepartment.Text;
        //    d.CREATETIME = DateTime.Now;
        //    d.CREATEDBY = CurrentUser.Name;
        //    if (Button1.Text == "Add")
        //    {
        //        num = bo.Add(d);
        //        lbo.WriteLog(CurrentUser.Name, "Add Department:" + d.DEPARTMENT);
        //    }
        //    else
        //    {
        //        d.ID = int.Parse(Request.QueryString["DID"].ToString());
        //        num = bo.Update(d);
        //        lbo.WriteLog(CurrentUser.Name, "Edit Department:" + d.DEPARTMENT);
        //    }
        //    if (num > 0)
        //    {
        //        txtDepartment.Text = "";
        //        txtDescription.Text = "";
        //        Button1.Text = "Add";
        //        //AlertMessage("Save success");
        //    }
        //    LoadData();
        //}

    }
}